package com.artisan.admin.controllers;

import com.artisan.admin.resultModels.MessageBase;
import com.artisan.admin.resultModels.adPositionResultModels.AdPositionResultModel;
import com.artisan.admin.resultModels.adTypeResultModels.AdTypeResultModel;
import com.artisan.domain.dto.AdPositionDto;
import com.artisan.domain.dto.AdTypeDto;
import com.artisan.domain.serviceInterface.IAdPositionService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 广告位置控制器
 */
@RequestMapping("/api/adPosition")
@RestController
@Api("广告位置模块")
@ApiOperation(value = "广告位置模块")
public class AdPositionController {
    private final IAdPositionService adPositionService;
    public AdPositionController(IAdPositionService adPositionService){this.adPositionService = adPositionService;}

    /**
     * 获得广告位置列表
     * @param status 状态
     */
    // GET /list
    @ApiOperation(value = "获得广告位置列表")
    @ApiImplicitParams(
            @ApiImplicitParam(paramType = "query", name = "status", dataType = "Int", required = true, value = "状态", defaultValue = "1")
    )
    @ApiResponses(@ApiResponse(code = 200, response = AdPositionResultModel.class, message = "成功"))
    @RequestMapping(value ={"/list"}, method = {RequestMethod.GET})
    public MessageBase getList(@RequestParam(value = "status")int status) {
        MessageBase result = new MessageBase();
        List<AdPositionDto> dtos = this.adPositionService.findList(status);

        ArrayList<AdPositionResultModel> models  = new ArrayList<>();

        dtos.forEach(dto -> {
            AdPositionResultModel model = new AdPositionResultModel();
            model.setId(dto.getId());
            model.setName(dto.getName());

            models.add(model);
        });

        result.setData(models);
        return result;
    }
}
